﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.RightsManagement;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace _05_03控件命令绑定
{
	public class MainViewModel:PorpertyChange
	{
		public MyCommandParam ShowCommand { get; set; }
		public MyCommandNoParam ShowCommand1 { get; set; }

		public MyCommand ShowCommand2 { get; set; }
		public MyCommand ShowCommand3 { get; set; }
		public MyCommand LogIn { get; set; }

        private string name;

		public string Name
		{
			get { return name; }
			set { name = value; Changed(); }
		}

		private string password;

		public string Password
		{
			get { return password; }
			set { password = value; Changed(); }
		}


		private string button1Content;
		public string Button1Content
		{
			get { return button1Content; }
			set 
			{
				button1Content = value;
				Changed();    
            }
		}

		private string button2Content;
		public string Button2Content
		{
			get { return button2Content; }
			set { button2Content = value; Changed(); }
		}

		public MainViewModel() 
		{
			//ShowCommand = new MyCommandParam(ExecuteShowCommand, CanExecuteShowCommand);

			//ShowCommand1 = new MyCommandNoParam(ExecuteShowCommandNoParam, CanExecuteShowCommand);

			ShowCommand2 = new MyCommand(ExecuteShowCommand, CanExecuteShowCommand);

			ShowCommand3 = new MyCommand(ExecuteShowCommandNoParam, CanExecuteShowCommand);

			LogIn = new MyCommand(ExecuteLogin,CanExecuteLogin);


        }

		public void Show()
		{
			MessageBox.Show("点击了控件");
		}

		private void ExecuteShowCommand(object parameter)
		{
			// 执行命令操作，可以使用parameter参数传递数据
			Button1Content = parameter.ToString();

		}

		private void ExecuteShowCommandNoParam()
		{
			// 执行命令操作，可以使用parameter参数传递数据
			Button2Content = "无参数的委托命令";

		}
		private bool CanExecuteShowCommand(object parameter)
		{
			// 返回一个布尔值，表示命令是否可执行
			return true;
		}


        private void ExecuteLogin(object parameter)
        {
            // 执行登录操作
        }

        private bool CanExecuteLogin(object parameter)
        {
            return !string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Password);
        }
    }
}
